import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop_z/config/service_url.dart';
import 'package:flutter_shop_z/pages/details_page.dart';

class FloorContent extends StatelessWidget {
  final List floorDaTitleList;
  final List floorGoodsListOne;
  final List floorGoodsListTow;
  final List floorGoodsListThree;
  FloorContent(this.floorDaTitleList, this.floorGoodsListOne,
      this.floorGoodsListTow, this.floorGoodsListThree);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          _title(floorDaTitleList[0]),
          _firstRow(context, floorGoodsListOne),
          _otherGoodsItem(context, floorGoodsListOne),
          _title(floorDaTitleList[1]),
          _firstRow(context, floorGoodsListTow),
          _otherGoodsItem(context, floorGoodsListTow),
          _title(floorDaTitleList[2]),
          _firstRow(context, floorGoodsListThree),
          _otherGoodsItem(context, floorGoodsListThree),
        ],
      ),
    );
  }

//标题
  Widget _title(category) {
    return Container(
      color: Color.fromRGBO(100, 30, 176, 0.3),
      width: ScreenUtil().setWidth(750),
      padding: EdgeInsets.all(8),
      child: Row(
        children: <Widget>[
          Image.network("${serviceUrl}${category['categoryImg']}",
              height: ScreenUtil().setHeight(50)),
          Text(category['categoryName']),
        ],
      ),
    );
  }

  //前三个商品
  //1 2
  //1 3
  Widget _firstRow(context, List firsList) {
    return Row(
      children: <Widget>[
        _goodsItem(context, firsList[0], 748),
        Column(
          children: <Widget>[
            _goodsItem(context, firsList[1], 374),
            _goodsItem(context, firsList[2], 374),
          ],
        )
      ],
    );
  }

  Widget _otherGoodsItem(context, List goodsList) {
    return Row(
      children: <Widget>[
        _goodsItem(context, goodsList[3], 374),
        _goodsItem(context, goodsList[4], 374)
      ],
    );
  }

  Widget _goodsItem(context, goods, height) {
    return Container(
      width: ScreenUtil().setWidth(374),
      height: ScreenUtil().setHeight(height),
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
            top: BorderSide(color: Colors.black12, width: 1),
            bottom: BorderSide(color: Colors.black12, width: 1),
            left: BorderSide(color: Colors.black12, width: 1),
            right: BorderSide(color: Colors.black12, width: 1),
          )),
      child: InkWell(
        onTap: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) {
            return new DetailsPage(goods['commodityId']);
          }));
        },
        child: Column(
          children: <Widget>[
            Image.network(
              "${serviceUrl}goods/${goods['categoryId']}/${goods['categorySubId']}/${goods['commodityImg']}",
              fit: BoxFit.fill,
              height: ScreenUtil().setHeight(height - 100),
              width: ScreenUtil().setWidth(374),
            ),
            Text("￥${goods['commodityDiscountPrice']}"),
            Text(
              "￥${goods['commodityOriginalPrice']}",
              style: TextStyle(
                  decoration: TextDecoration.lineThrough, //中划线
                  color: Colors.grey),
            )
          ],
        ),
      ),
    );
  }
}
